using IQIGame.Onigao.Framework.Serialization;
using System.Collections.Generic;

namespace IQIGame.Onigao.Game
{
    public partial class CFSMConditionPartCfg : ISerializeByteBuf
    {
        public virtual void DeSerialize(ByteBuf _buf)
        {
            funcName = _buf.ReadString();
            isPublic = _buf.ReadBool();
            int count = _buf.ReadInt();
            paramTypes = new List<CFSMParamType>(count);
            paramValues = new List<object>(count);
            for (int i = 0; i < count; i++)
            {
                //type
                CFSMParamType type = (CFSMParamType)_buf.ReadByte();
                //value
                object p = CFSMSerializeUtil.ReadValueByType(_buf, type);

                paramTypes.Add(type);
                paramValues.Add(p);
            }
            compareOPeration = (CompareOperation)_buf.ReadByte();
            targetType = (CFSMParamType)_buf.ReadByte();
            targetValue = CFSMSerializeUtil.ReadValueByType(_buf, targetType);
            prevLogicOperation = (LogicOperation)_buf.ReadByte();
        }

        public virtual void Serialize(ByteBuf _buf)
        {
            _buf.WriteString(funcName);
            _buf.WriteBool(isPublic);
            _buf.WriteInt(paramValues.Count);
            for (int i = 0; i < paramValues.Count; i++)
            {
                CFSMParamType type = paramTypes[i];
                object value = paramValues[i];

                //type
                _buf.WriteByte((byte)type);
                //value
                CFSMSerializeUtil.WriteValueByType(_buf, type, value);
            }
            _buf.WriteByte((byte)compareOPeration);
            _buf.WriteByte((byte)targetType);
            CFSMSerializeUtil.WriteValueByType(_buf, targetType, targetValue);
            _buf.WriteByte((byte)prevLogicOperation);
        }
    }
}